package com.cn.namesrv;

import com.cn.common.BrokerAppStore;
import com.cn.common.BrokerCluster;
import com.cn.common.BrokerEntity;
import com.cn.common.BrokersUrlStore;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;

public class NameRemoveBroker {

    public static void close(ChannelHandlerContext ctx) {
        BrokerEntity broker = BrokerAppStore.get(ctx);
        if (broker != null) {
            BrokersUrlStore.del(broker.getAddress());
            BrokerAppStore.del(ctx);
            BrokerCluster.del(broker);
        }

        //关闭通道
        ctx.channel().close().addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture channelFuture) throws Exception {
                System.out.println("与失去联系的客户端通道正确关闭！");
            }
        });
    }

}
